﻿
//处理弹窗设置参数
function getDialog(option) {

    var obj = $.extend({ title: false,
        cancel: false,
        fixed: true,
        lock: false,
        drag:false,
        padding: 0
    }, option)
    return art.dialog(obj);

}

//给弹窗绑定提示信息和回调函数
function pageReplace(data, msg, ok, cancel) {

    data = data.replace('#title#', msg)
    if (ok == undefined || ok == "") {
        data = data.replace("#ok#", "$.dialogHelper.close();");
    }
    else {
        data = data.replace("#ok#", ok + "();");
    }

    if (cancel == undefined || cancel == "") {
        data = data.replace("#cancel#", "$.dialogHelper.close();");
    }
    else {
        data = data.replace("#cancel#", cancel + "();");
    }

    return data;
}

$.dialogHelper = {

    alertPageUrl: "/JS/artDialog/alert.htm",
    successPageUrl: "/JS/artDialog/alert_sucess.htm",
    smilePageUrl: "/JS/artDialog/alert_smile.htm",
    comfirmPageUrl: "/JS/artDialog/confirm.htm",
    defaultId: "syhdialogid",

    alert: function (msg, status, ok, option) {

        var path = this.alertPageUrl;
        if (status == "alert") {
            path = this.alertPageUrl;
        }
        else if (status == "success") {
            path = this.successPageUrl;
        }
        else if (status == "smile") {
            path = this.smilePageUrl;
        }

        option = $.extend({ id: this.defaultId, lock: true })
        var openWin = getDialog(option);

        $.get(path, function (data) {
            data = pageReplace(data, msg, ok)
            openWin.content(data);
        }, "text");
    },

    confirm: function (msg, ok, cancel, option) {
        option = $.extend({ id: this.defaultId, lock: true });
        var openWin = getDialog(option);
        $.get(this.comfirmPageUrl, function (data) {
            data = pageReplace(data, msg, ok, cancel)
            openWin.content(data);
        }, "text");

    },

    open: function (url, option, showCallBack) {
        var openWin = getDialog(option);
        $.get(url, function (data) {
            openWin.content(data);
            if (showCallBack) {
                showCallBack();
            }
        }, "text");

    },

    close: function (DialogId) {
        if (DialogId == undefined) {
            art.dialog({ id: this.defaultId }).close();
        } else {
            art.dialog({ id: DialogId }).close();
        }
    },

    closeAll: function () {
        var list = art.dialog.list;
        for (var i in list) {
            list[i].close();
        };
    }

}
